package com.game.common.utils;

import java.util.*;

public class CalendaUtils {

    private static List<Map<String,Object>> getInitMonthMapWithZero(){
        List<Map<String,Object>> list = new ArrayList<>();
        Calendar c = Calendar.getInstance();
        for(int i = 0; i < 12; i ++){
            int k = c.get(Calendar.YEAR);
            int j = c.get(Calendar.MONTH) + 1 - i;
            Map<String,Object> map = new HashMap<>();
            if(j >= 1){
                map.put("year",k);
                map.put("month",j);
            } else {
                int p = 11 - i;//剩余循环次数
                int m = c.get(Calendar.YEAR) - 1;
                int n = c.get(Calendar.MONTH) + 2 + p;
                map.put("year",m);
                map.put("month",n);
            }
            list.add(map);
        }
        return list;
    }


    public static void main(String[] args) {
        List<Map<String, Object>> initMonthMapWithZero = getInitMonthMapWithZero();
        initMonthMapWithZero.forEach(x->{
            System.out.println("year: "+ x.get("year")+"     month: "+ x.get("month"));
        });
    }

}
